package com.ruoyi.project.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.product.domain.InsReagentOrderListDetail;
import com.ruoyi.project.product.service.IInsReagentOrderListDetailService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 试剂订单试剂类型详细数量Controller
 *
 * @author taney
 * @date 2020-11-23
 */
@AllArgsConstructor
@RestController
@RequestMapping("/product/orderListDetail")
public class InsReagentOrderListDetailController extends BaseController {

    private final IInsReagentOrderListDetailService iInsReagentOrderListDetailService;

    /**
     * 查询试剂订单试剂类型详细数量列表
     */
    @PreAuthorize("@ss.hasPermi('product:orderListDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsReagentOrderListDetail insReagentOrderListDetail) {
        startPage();
        LambdaQueryWrapper<InsReagentOrderListDetail> lqw = new LambdaQueryWrapper<InsReagentOrderListDetail>();
        if (insReagentOrderListDetail.getAmount() != null) {
            lqw.eq(InsReagentOrderListDetail::getAmount, insReagentOrderListDetail.getAmount());
        }
        List<InsReagentOrderListDetail> list = iInsReagentOrderListDetailService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出试剂订单试剂类型详细数量列表
     */
    @PreAuthorize("@ss.hasPermi('product:orderListDetail:export')")
    @Log(title = "试剂订单试剂类型详细数量", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InsReagentOrderListDetail insReagentOrderListDetail) {
        LambdaQueryWrapper<InsReagentOrderListDetail> lqw = new LambdaQueryWrapper<InsReagentOrderListDetail>(insReagentOrderListDetail);
        List<InsReagentOrderListDetail> list = iInsReagentOrderListDetailService.list(lqw);
        ExcelUtil<InsReagentOrderListDetail> util = new ExcelUtil<InsReagentOrderListDetail>(InsReagentOrderListDetail.class);
        return util.exportExcel(list, "orderListDetail");
    }

    /**
     * 获取试剂订单试剂类型详细数量详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:orderListDetail:query')")
    @GetMapping(value = "/{orderListId}")
    public AjaxResult getInfo(@PathVariable("orderListId") Integer orderListId) {
        return AjaxResult.success(iInsReagentOrderListDetailService.getById(orderListId));
    }

    /**
     * 新增试剂订单试剂类型详细数量
     */
    @PreAuthorize("@ss.hasPermi('product:orderListDetail:add')")
    @Log(title = "试剂订单试剂类型详细数量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsReagentOrderListDetail insReagentOrderListDetail) {
        return toAjax(iInsReagentOrderListDetailService.save(insReagentOrderListDetail) ? 1 : 0);
    }

    /**
     * 修改试剂订单试剂类型详细数量
     */
    @PreAuthorize("@ss.hasPermi('product:orderListDetail:edit')")
    @Log(title = "试剂订单试剂类型详细数量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsReagentOrderListDetail insReagentOrderListDetail) {
        return toAjax(iInsReagentOrderListDetailService.updateById(insReagentOrderListDetail) ? 1 : 0);
    }

    /**
     * 删除试剂订单试剂类型详细数量
     */
    @PreAuthorize("@ss.hasPermi('product:orderListDetail:remove')")
    @Log(title = "试剂订单试剂类型详细数量", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderListIds}")
    public AjaxResult remove(@PathVariable Integer[] orderListIds) {
        return toAjax(iInsReagentOrderListDetailService.removeByIds(Arrays.asList(orderListIds)) ? 1 : 0);
    }

    /**
     * 删除试剂订单试剂类型详细数量
     */
    @PreAuthorize("@ss.hasPermi('product:delOrderListDetailByOrderId:remove')")
    @Log(title = "试剂订单试剂类型详细数量", businessType = BusinessType.DELETE)
    @DeleteMapping("/delOrderListDetailByOrderId/{orderId}")
    public AjaxResult delOrderListDetailByOrderId(@PathVariable Long orderId) {
        LambdaQueryWrapper<InsReagentOrderListDetail> lqw = new LambdaQueryWrapper<>();
        lqw.eq(InsReagentOrderListDetail::getOrderId, orderId);
        iInsReagentOrderListDetailService.remove(lqw);
        return AjaxResult.success(orderId);
    }
}
